package net.edu_soft.ec.asset.service.impl;

import net.edu_soft.ec.asset.mapper.FactoryTypeMapper;
import net.edu_soft.ec.asset.pojo.FactoryType;
import net.edu_soft.ec.asset.pojo.FactoryTypeExample;
import net.edu_soft.ec.asset.service.FactoryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FactoryTypeServiceImpl implements FactoryTypeService {
    @Autowired
    private FactoryTypeMapper factoryTypeMapper;


    @Override
    public int insert(String name,Integer parentId) {
        FactoryType factoryType=new FactoryType();
        factoryType.setName(name);
        factoryType.setParentId(parentId);
        factoryType.setStatus(1);
        if(name==null || name.equals(" ")){
            return 0;
        }
        if (parentId==0){
            return factoryTypeMapper.insert(factoryType);
        }else{
            if (factoryTypeMapper.selectByPrimaryKey(parentId)==null){
                return factoryTypeMapper.insert(factoryType);
            }
        }
        return 0;
    }

    @Override
    public List<FactoryType> selectByExample(){
        FactoryTypeExample factoryTypeExample=new FactoryTypeExample();
        return  factoryTypeMapper.selectByExample(factoryTypeExample);
    }

    @Override
    public int deleteByPrimaryKey(Integer factoryTypeId) {
        return factoryTypeMapper.deleteByPrimaryKey(factoryTypeId);
    }
}
